package com.java2104.mapper;

import com.java2104.entity.Dept;
import com.java2104.entity.Employee;
import com.java2104.entity.Job;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EmployeeMapper {

    //待修改的方法
    List<Employee> findEmployees(Employee employee);

    int batchUpdateDeleteStatus(List<Integer> ids);

    @Update("update employee_inf set " +
            "name=#{name},card_id=#{cardId}," +
            "sex=#{sex},job_id=#{job.id}," +
            "education=#{education},email=#{email}," +
            "phone=#{phone},tel=#{tel}," +
            "party=#{party},qq_num=#{qqNum}," +
            "address=#{address},post_code=#{postCode}," +
            "birthday=#{birthday},race=#{race}," +
            "speciality=#{speciality},hobby=#{hobby}," +
            "remark=#{remark},dept_id=#{dept.id} " +
            "where id=#{id}")
    int updateByPrimaryKey(Employee employee);
    @Results({
            @Result(property = "dept", javaType = Dept.class, column = "dept_id",
                    one = @One(select = "com.java2104.mapper.DeptMapper.findByPrimaryKey")),
            @Result(property = "job", javaType = Job.class, column = "job_id",
                    one = @One(select = "com.java2104.mapper.JobMapper.findByPrimaryKey"))
    })
    @Select("select * from employee_inf where id=#{param1}")
    Employee findByPrimaryKey(Integer id);
    @Select("select count(*) from employee_inf where card_id=#{cardId}")
    int selectCardId(String cardId);
    @Insert("insert into employee_inf value(null,#{dept.id},#{job.id}," +
            "#{name},#{cardId},#{address},#{postCode},#{tel},#{phone},#{qqNum}," +
            "#{email},#{sex},#{party},#{birthday},#{race},#{education},#{speciality},#{hobby},#{remark},now(),0)")
    int insertEmployees(Employee employee);
}
